home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-17 | 92.2 KB | 2,585 lines | [TEXT/MPS ] |
- #
- # ****************************************************************************
- #
- # File Name: UserInterface.Lib
- #
- # Contains: Library of tasks that manipulate some aspect of the Human Interface.
- #
- # Written by: Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
- #
- # Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- #
- # ****************************************************************************
- # C h a n g e H i s t o r y (most recent first):
- # ****************************************************************************
- #
- # Vers Date Author Description
- # ---- -------- ------ ---------------------------------------------
- # <2.0.22> 12/16/93 KTA SizeWindow() - fixed bug where trying to size window smaller
- # than 20 pixels
- # <2.0.21> 12/2/93 KTA DialogCheck() - supports button descriptors, TypeStr() added
- # gTypeStrOverRide.
- # <2.0.20> 11/19/93 NAGA modify TCS format
- # <2.0.19> 11/19/93 KTA A couple of changes for INTL and Performance
- # <2.0.18> 11/11/93 KTA DialogCheck() - If no pFindStaticText is passed in, it will work
- # on any dialog.
- # <2.0.17> 9/22/93 KTA Removed a projector error message.
- # <2.0.16> 9/22/93 KTA Changed gEndTimer task references to reflect the task in which
- # the references are located.
- # <2.0.15> 9/13/93 KTA SelectButton(), SelectRadioButton(), selectCheckBox - added
- # support for selecting by ordinality.
- # <2.0.14> 9/13/93 KTA Updated TestLevel specification and DismissDialog() now supports
- # KeyEq('.').
- # <2.0.13> 9/9/93 KTA SelectMenuItem(), KeyEq() - Changed output line so it does not
- # say 'About to …'
- # <2.0.12> 9/7/93 KTA KeyEq() - Added pOtherKey := 3 (controlkey).
- # <2.0.11> 9/1/93 KTA Parameter Updates
- # <2.0.10> 9/1/93 KTA More header updates - Window section
- # <2.0.9> 9/1/93 KTA Updated task headers and parameters.
- # <2.0.8> 8/25/93 KTA Added support for parity checking the TCS stack.
- # <2.0.7> 7/30/93 KTA Updates to DismissDialog(), DialogHandler(), and DialogCheck(),
- # also updated a couple of descriptors that were still contained
- # within lists.
- # <2.0.6> 7/23/93 KTA CloseWindow() - needed a wait(2) and call IsStandardFile().
- # <2.0.5> 7/22/93 KTA FindWindow() - if specifier is a descriptor needed a Dammit
- # operator (!)
- # <2.0.4> 7/20/93 KTA A couple of more changes to support FindWindow().
- # <2.0.3> 7/19/93 KTA Updated for FindWindow to handle descriptors.
- # <2.0.2> 7/7/93 KTA Changed DismissDialog() so it would properly verify whether
- # dialog was dismissed.
- # <2.0.1> 7/6/93 KTA Performance support and other misc. changes.
- # <1+> 5/21/93 NAGA Adding header and porting old files to follow new standards
- #
- # ****************************************************************************
- #
-
-
- ########################################################################
- # External libraries
- #=======================================================================
- Libraries "Geometry.lib","String.Lib","Output.lib","TCS.lib", "StandardFile.lib";
-
-
- #=======================================================================
- # Menu related tasks:
- #=======================================================================
-
- ########################################################################
- # SelectMenuItem(pMenu1, pMenu2, pMenu3)
- #=======================================================================
- # Author: Kevin Avoy
- # Description: Selects the menu item by its title or ordinality.
- # All parameters are expected to be the same type.
- # Parameters: pMenu1 := Menu item to be selected.
- # pMenu2 := Menu name if non-hier menu and
- # Level 2 menu item if hier menu.
- # pMenu3 := "" if non-hier menu.
- # Menu name if hier menu.
- # Returns: menuTitle - MenuItem name that selection was successful
- # 0 - Couldn't select menu item
- # Notes: It is not mandatory to specify input parameters 'pMenu2'
- # or 'pMenu3'. In that case, default value, "",
- # will be used.
- #=======================================================================
- # History:
- # KTA 7/6/93 Performance support: Call (gBeginTimer);
- # KTA 7/6/93 Readded regularExpression support
- # KTA 9/9/93 Changed output line so it does not say 'About to …'
- # KTA 9/21/93 Changed gBeginTimer to gPreSelectMenuItemHook, gPostSelectMenuItemHook
- ########################################################################
- TASK SelectMenuItem(pMenu1, pMenu2 := "", pMenu3 := "")
- begin
- returnVal := 0;
- #println "SelectMenuitem∂( ",pMenu1,',',pMenu2,',',pMenu3,"∂)";
- if not (match [window o:1 s:Dialog c:0 g:0 z:0]!)
- begin
- if ((Typeof(pMenu1) = 'string') or (Typeof(pMenu1) = 'regularExpression'))
- begin
- if (pMenu3 = "") # Match non-hier menus
- ourMenuItem := match [menuItem t: pMenu1 m:[menu t: pMenu2]];
- else # Match hier menus
- ourMenuItem :=match [menuItem t:pMenu1
- m:[menuitem t:pMenu2
- m:[menu t:pMenu3]]];
- end;
- else
- begin
- if not(pMenu3) # Match non-hier menus
- ourMenuItem := match [menuItem o:pMenu1 m:[menu o:pMenu2]];
- else # Match hier menus
- ourMenuItem :=match [menuItem o:pMenu1
- m:[menuitem o:pMenu2
- m:[menu o:pMenu3]]];
- end;
-
- if (ourMenuItem) # Not there
- begin
- if (ourMenuItem.e) # enabled
- begin
- menuTitle := ourMenuItem.t;
- LogStr("Selecting the '{menuTitle}' menu item");
- if (global gMacstiming) and (global gPreSelectMenuItemHook)
- # possible changes to collect macstime data accurately
- # after the menu item is selcted Finder doesn't get time so the AppleEvent
- # can be parsed and executed by the MacsTime CDEV - So we need to start
- # MacsTime before the menu select
- Call (gPreSelectMenuItemHook);
-
- select ourMenuItem!;
-
- if not(gMacsTiming) and (global gPostSelectMenuItemHook)
- Call (gPostSelectMenuItemHook);
-
- returnVal := menuTitle;
- end;
- else
- begin
- menuTitle := ourMenuItem.t;
- LogStr("!@#$% Menu item {menuTitle} is not enabled to select.");
- end;
- end;
- else
- LogStr("!@#$% Could not find menu item {pMenu1} to select");
- end;
- else
- begin
- LogStr("!@#$% Dialog present can't select menuItems");
- DialogCheck(, 1); # Attempt to dismiss the dialog
- end;
-
- return(returnVal);
- end; # SelectMenuItem()
-
- #########################################################################
- # FindMenu(pTheMenuItem)
- #=======================================================================
- # Author: KTA
- # Description: Returns the Menu(s) in which <pTheMenuItem> is contained.
- # Parameters: pTheMenuItem := Title of the menuitem to be searched for.
- # Returns: 0 - Can't match <pTheMenuItem>.
- # {theMenu,""} - for a nonHierarchical menu.
- # {theHMenuItem, theMenu} - if its hierarchical.
- # Example: MyMenu := FindMenu('Paste');
- #=======================================================================
- # History:
- #
- #########################################################################
- TASK FindMenu(pTheMenuItem)
- begin
- MenuName := match[menuitem t:pTheMenuItem];
- if (MenuName)
- begin
- IsMenu := descType(MenuName.m);
- if (IsMenu = 'menu')
- begin
- theMenu := MenuName.m.t;
- Return({theMenu,""});
- end;
- else If (IsMenu = 'menuItem')
- begin
- theHMenuItem := MenuName.m.t;
- MenuName := match [menuItem t:pTheMenuItem
- m:[menuitem t:theHMenuItem
- m:[menu t:?theMenu]]];
- Return({theHMenuItem, theMenu});
- end;
- end;
- else Return(0);
- end; # FindMenu()
-
- #########################################################################
- # KeyEq(pKeyEquiv,pOtherkey, pNumTimes)
- #========================================================================
- # Author: KTA
- # Description: This routine will select the Keyboard Equiv <pKeyEquiv>
- # Parameters: pKeyEquiv - string holding character to be typed with
- # command key down.
- # pOtherkey - integer - representing special keys to hold
- # down in conjunction with the command key
- # 1 - Shift key
- # 2 - Option key
- # 3 - Control key
- # pNumTimes - integer - representing number of times to type keyEq.
- # Returns: None
- # Examples: KeyEq("q");
- #========================================================================
- # History:
- # KTA 7/2/93 Added pNumTimes parameter for number of times to type KeyEq.
- # KTA 7/6/93 Performance support: Call (gBeginTimer);
- # KTA 9/7/93 Added pOtherKey := 3 (controlkey)
- # KTA 9/9/93 Changed output line so it does not say 'About to …'
- # KTA 9/21/93 Changed gBeginTimer to gPreKeyEqHook
- #########################################################################
- TASK KeyEq(pKeyEquiv, pOtherkey := 0, pNumTimes := 1)
- begin
- KeyList := { '',''};
- if (pOtherkey =1)
- KeyList := {ShiftKey,'-Shift'};
- else if (pOtherkey = 2)
- KeyList := {Optionkey,'-Option'};
- else if (pOtherkey = 3)
- KeyList := {Controlkey,'-Control'};
-
- WhichKey := KeyList[2];
- LogStr("Pressing the ∂('{pKeyEquiv}'∂) key and the Command{WhichKey} key {pNumTimes} times");
-
- pressKey k:{ commandKey,KeyList[1]};
- For i := 1 to pNumTimes
- begin
- if (global gPreKeyEqHook)
- Call (gPreKeyEqHook);
- type k : { pKeyEquiv };
- end;
-
- releaseKey k:{ commandKey,KeyList[1] };
- end; # KeyEq()
-
-
- #=======================================================================
- # Window related tasks:
- #=======================================================================
- # Description: This section contains VU code for running tests on the
- # basic controls of a window.
- #
- # *** The main task in this section is TestWindow(). It is used to
- # perform a number of window test automatically.
- #
- # The window related tasks in this library are grouped in the
- # following logical order:
- #
- # TestWindow(pSpecifier, pFunctionList, pRestoreWindow, pNumTimes, pDragXY)
- # WindowFunction(pSpecifier, pTheFunction, pDragXY, pDestinationPoint)
- # DragAcrossScreens(pSpecifier,pDragXY)
- # SizeAcrossScreens(pSpecifier, pDragXY)
- # AdjustRectToScreen(pTheRect)
- # CoverCompletely (pFirstWindow, pSecondWindow)
- # ResetWindow(pTheWindow)
- # SelectWindow(pSpecifier)
- # UnCoverWindow(pSpecifier, pFrontWindow)
- # DragWindow(pHorizontalPixels, pVerticalPixels, pSpecifier,pAbsolutely)
- # SizeWindow(pPixelsWide, pPixelsHigh, pSpecifier, pAbsolutely)
- # ZoomWindow(pSpecifier)
- # CloseWindow(pHowClose,pOverWrite,pSpecifier,pNewDocName)
- # ScrollWindow(pWhichScrollBar,pDesirePosition,pMaxPosition)
- # GetVHScrollBars()
- # CloseAllWindows()
- # FindWindow(pSpecifier)
- # GetRandomPointsRelativeToWindow(pInset, pSpecifier, pNumPts)
- #
- #
- #
- #
- #
- #
- #
- # Copyright Apple Computer, Inc. 1985-1990
- # All rights reserved
- #
- #========================================================================
- # History:
- #
- #########################################################################
-
-
- #########################################################################
- # TestWindow(pSpecifier,pFunctionList,pRestoreWindow,pNumTimes,pDragXY)
- #=======================================================================
- # Author: Nick Vaccaro
- #
- # Description: Performs the specified functions as defined in the input
- # parameter pFunctionList. If pFunctionList is not passed,
- # or is passed as 0, then the following operations are
- # performed on the window specified by input parameter
- # pSpecifier. The default behavior will perform the
- # following behaviors on the frontmost window* (see *NOTE).
- # Listed below is the list of function numbers and a brief
- # description of what that particular function does:
- #
- # #0 Complete Window Test
- # Performs functions 1 through 17
- # (17 is done twice - zoom & zoom back)
- # #1 Resize to random width and height.
- # #2 Attempt resize to 20,20 (should not allow it)
- # #3 Scroll the vertical scroll bar to random location.
- # #4 Scroll the vertical scroll bar to end location.
- # #5 Scroll the vertical scroll bar to beginning location.
- # #6 Scroll the vertical scroll bar to original location.
- # #7 Scroll the horizontal scroll bar to random location.
- # #8 Scroll the horizontal scroll bar to end location.
- # #9 Scroll the horizontal scroll bar to beginning location.
- # #10 Scroll the horizontal scroll bar to original location.
- # #11 Resize window to largest possible and then
- # #12 Resize back to smallest window size
- # #13 Size window across screen border to second screen
- # (if 2 screens) and back
- # #14 Drag window across screen border and back
- # #15 Drag random location and back to original location
- # #16 Drag window back to original location.
- # #17 Zoom.
- # #18 Complete Window Size Test
- # Performs functions 1,2,11,12, and 13
- # #19 Complete Window Scroll Test
- # Performs functions 3,4,5,6,7,8,9, and 10
- # #20 Complete Window Drag Test
- # Performs functions 14,15, and 16
- # #21 Complete Window Zoom Test
- # Performs function 17 twice (zoom - zoom back)
- # #22 A More Complete Window Scroll Test
- # Performs functions 2,3,4,5,6,7,8,9, and 10.
- # This is the same as #19 except it sizes the
- # window to the smallest possible size. This
- # is better in that it is more likely for the
- # scrollbars to be active.
- # #23 A More Complete Window Drag Test
- # Performs functions 2,14,15, and 16
- # This is the same as #20 except it sizes the
- # window to the smallest possible size. This
- # is better in that it is more likely for the
- # window to be able to be dragged across screen
- # boundaries.
- #
- # Parameters: pSpecifier - Title or Ordinality or partial window descriptor
- # of window to be tested
- # If this parameter is not passed, default
- # behavior of Tasks will be used (generally the
- # frontmost window - see *NOTE below)
- #
- # pFunctionList - A list containing the functions to be
- # executed and the number of times to exercize
- # each function. The functions will be executed
- # in the order that they are defined. The default
- # is to execute all tests once. The pFunctionList
- # parameter can have the following formats:
- #
- # integer:
- # Number of a single test to run once.
- # Functions are numbered above.
- # 0 to execute full sequence once.
- #
- # list of integers:
- # A list of test numbers to run -
- # each test will be run once and
- # in the same order that they appear
- # in the list.
- #
- # list of lists:
- # A list of {test#,#times} lists
- # where test# is the number of the
- # test and #times is the number of
- # times to execute that test. Each
- # list will be processed in order.
- # If an item in the main list is an
- # integer and not a list, that test
- # number will be executed once.
- #
- # pRestoreWindow - 1 to restore window to original size,
- # location, and scrollbar status.
- # 0 not to restore window
- #
- # pNumTimes - integer for number of times to execute test
- #
- # pDragXY - Upper Left-Top corner to drag window to
- #
- # Returns: 0 - Couldn't find specified window
- # 1 - Executed OK
- #
- # Assumptions: None
- #
- #========================================================================
- # History:
- #
- #########################################################################
- TASK TestWindow(pSpecifier := 0, pFunctionList := 0, pRestoreWindow := 0, pNumTimes := 1, pDragXY := {0,20})
- begin
- if (global gScreenInset)
- pDragXY := {gScreenInset[1], gScreenInset[2]};
- global OrigScrollBars := 0; # default to scrollbars at beginning
- returnVal := 0;
-
- # get the window's original status - if we can't find it, return 0
- originalWindowDesc := FindWindow(pSpecifier);
- if (originalWindowDesc)
- begin
-
- # set all original window variable information
- originalOrd := originalWindowDesc.o;
- if (originalOrd <> 1)
- originalWindowDesc := SelectWindow(pSpecifier);
- originalOrd := originalWindowDesc.o;
- theTitle := originalWindowDesc.t;
- oldRect := originalWindowDesc.r;
- theDesc := [window t:theTitle o:originalOrd]; # Partial window descriptor
-
- # and scroll bar positions
- OrigScrollBars := collect [scrollbar w:[window t:theTitle o:originalOrd]]!;
- if (card OrigScrollBars >= 2) begin
- hscroll := OrigScrollBars[2];
- vscroll := OrigScrollBars[1];
- end;
- else if (card OrigScrollBars = 1)
- vscroll := OrigScrollBars[1];
-
- if (hscroll)
- OrigScrollBars := {vscroll.s,hscroll.s};
- else if (vscroll)
- OrigScrollBars := {vscroll.s};
-
- # if pFunctionList = 0, run default behavior
- if (pFunctionList = 0) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Test...");
- #pFunctionList := {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,17};
- pFunctionList := {17,17,12,11,1,3,4,5,6,7,8,9,10,13,14,15,11};
- end;
-
- # first, drag the window onto screen to assure more success at functions
- # Drag it to the desired location (if needed)
- if not ((tempRect[1] = pDragXY[1]) and (tempRect[2] = pDragXY[2]))
- if global gDoWindowList[3] # if dragging is available
- DragWindow(pDragXY[1],pDragXY[2],theDesc,1); # Call with partial window descriptor
-
-
- for iterationNum := 1 to pNumTimes do begin
- # Now perform our test(s)
- if (TypeOf(pFunctionList) = "integer") begin # it's a single test
- WindowFunction(theDesc, pFunctionList, pDragXY, oldRect);
- end;
- else begin # it's a list of tests
- for currentFunction := 1 to card pFunctionList do begin
- theFunction := pFunctionList[currentFunction];
- if (TypeOf(theFunction) = "list") begin
- for tempCount := 1 to theFunction[2] begin
- if (WindowFunction(theDesc,theFunction[1],pDragXY,oldRect))
- returnVal := 1;
- end;
- end;
- else begin
- if (WindowFunction(theDesc,theFunction,pDragXY,oldRect))
- returnVal := 1;
- end;
- end;
- end;
- end;
-
- if (pRestoreWindow)
- ResetWindow(originalWindowDesc);
-
- returnVal := 1;
- end;
- else
- LogStr("Couldn't find specified window for TestWindow");
-
- return(returnVal);
- end; # TestWindow()
-
-
- #########################################################################
- # WindowFunction(pSpecifier, pTheFunction, pDragXY,pDestinationPoint)
- #=======================================================================
- # Author: NJV
- # Description: Performs the specified function defined in the input
- # parameter pTheFunction to the window specified by pSpecifier.
- # Listed below is the list of function numbers and a brief
- # description of what that particular function does:
- #
- # #1 Resize to random width and height.
- # #2 Attempt resize to 20,20 (should not allow it)
- # #3 Scroll the vertical scroll bar to random location.
- # #4 Scroll the vertical scroll bar to end location.
- # #5 Scroll the vertical scroll bar to beginning location.
- # #6 Scroll the vertical scroll bar to original location.
- # #7 Scroll the horizontal scroll bar to random location.
- # #8 Scroll the horizontal scroll bar to end location.
- # #9 Scroll the horizontal scroll bar to beginning location.
- # #10 Scroll the horizontal scroll bar to original location.
- # #11 Resize window to largest possible
- # #12 Resize back to smallest window size
- # #13 Size window across screen border to second screen
- # (if 2 screens) and back
- # #14 Drag window across screen border and back
- # #15 Drag window to random location.
- # #16 Drag window to location specified by pDestinationPoint.
- # #17 Zoom.
- # #18 Complete Window Size Test
- # Performs functions 1,2,11,12, and 13
- # #19 Complete Window Scroll Test
- # Performs functions 3,4,5,6,7,8,9, and 10
- # #20 Complete Window Drag Test
- # Performs functions 14,15, and 16
- # #21 Complete Window Zoom Test
- # Performs function 17 twice (zoom - zoom back)
- # #22 A More Complete Window Scroll Test
- # Performs functions 2,3,4,5,6,7,8,9, and 10
- # This is the same as #19 except it sizes the
- # window to the smallest possible size. This
- # is better in that it is more likely for the
- # scrollbars to be active.
- # #23 A More Complete Window Drag Test
- # Performs functions 2,14,15, and 16
- # This is the same as #20 except it sizes the
- # window to the smallest possible size. This
- # is better in that it is more likely for the
- # window to be able to be dragged across screen
- # boundaries.
- #
- # Parameters: pSpecifier - Title of window to be tested
- #
- # pTheFunction - The number of the test to run
- #
- # pDragXY - Left-Top point (list of {left,top}) to drag
- # window to. (used if pTheFunction = 13 or 14)
- #
- # pDestinationPoint - Left/Top point (list of {left,top}) of
- # original window (used if pTheFunction = 16)
- #
- # Returns: 0 - Couldn't perform specified Task
- # 1 - Executed OK
- #
- # Assumptions: None.
- #
- # *NOTE: The TestWindow() function provides much more versatility
- # than this routine. WindowFunction is called by TestWindow.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK WindowFunction(pSpecifier, pTheFunction, pDragXY, pDestinationPoint)
- begin
- if (global gScreenInset)
- inset := gScreenInset;
- else
- inset := { 0,20,0,0};
- # if the user wants a multiple function (#18-#23), set FunctionList
- # accordingly
- if ((pTheFunction >= 18) and (pTheFunction <= 23)) begin
-
- # reset FunctionList
- if (pTheFunction = 18) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Size Test...");
- FunctionList := {1,2,11,12,13};
- end;
- else if (pTheFunction = 19) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Scroll Test...");
- FunctionList := {3,4,5,6,7,8,9,10};
- end;
- else if (pTheFunction = 20) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Drag Test...");
- FunctionList := {14,15,16};
- end;
- else if (pTheFunction = 21) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Zoom Test...");
- FunctionList := {17,17};
- end;
- else if (pTheFunction = 22) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Scroll Test - Will Shrink Window First...");
- FunctionList := {2,3,4,5,6,7,8,9,10};
- end;
- else if (pTheFunction = 23) begin
- println;
- println "===========================================================================";
- LogStr("Starting Complete Window Drag Test - Will Shrink Window First...");
- FunctionList := {2,14,15,16};
- end;
-
- # now execute each test using recursion
- noError := 1; # no errors yet
- for each item in FunctionList begin
- if not (WindowFunction(pSpecifier,item,pDragXY,pDestinationPoint))
- foundError := 1;
- end;
- return(foundError);
- end;
-
- if (pTheFunction = 1) #1 Resize to random width and height.
- return(SizeWindow('random','random',pSpecifier)); #1
-
- else if (pTheFunction = 2) #2 Attempt resize to 20,20 (should not allow it)
- return(SizeWindow(20,20,pSpecifier)); #2
-
- else if ((pTheFunction >= 3) and (pTheFunction <= 10)) begin
- # get the old value of the scroll bars to replace scrollbars as they were found.
- theScrollBars := GetVHScrollBars();
- vertical := theScrollBars[1];
- horizontal := theScrollBars[2];
- oldVertical := vertical.s;
- oldHorizontal := horizontal.s;
-
- if (pTheFunction = 3) #3 Scroll the vertical scroll bar to random location.
- return(ScrollWindow('V')); #3
-
- else if (pTheFunction = 4) #4 Scroll the vertical scroll bar to end location.
- return(ScrollWindow('V',1,1)); #4
-
- else if (pTheFunction = 5) #5 Scroll the vertical scroll bar to beginning location.
- return(ScrollWindow('V',0,1)); #5
-
- else if (pTheFunction = 6) #6 Scroll the vertical scroll bar to original location.
- return(ScrollWindow('V',oldVertical[1],oldVertical[2])); #6
-
- else if (pTheFunction = 7) #7 Scroll the horizontal scroll bar to random location.
- return(ScrollWindow('H')); #7
-
- else if (pTheFunction = 8) #8 Scroll the horizontal scroll bar to end location.
- return(ScrollWindow('H',1,1)); #8
-
- else if (pTheFunction = 9) #9 Scroll the horizontal scroll bar to beginning location.
- return(ScrollWindow('H',0,1)); #9
-
- else #10 Scroll the horizontal scroll bar to original location.
- return(ScrollWindow('H',oldHorizontal[1],oldHorizontal[2])); #10
- end;
-
- else if (pTheFunction = 11) begin #11 Resize window to largest possible
- # Match to get new rect
- theWind := FindWindow(pSpecifier);
- if not (theWind)
- return(0);
- else
- newRect := theWind.r;
- # get screen coordinates
- match [screen r:?theScreenRect m:true]!;
-
- #11 Resize window to largest possible
- return(SizeWindow(theScreenRect[3]-newRect[1]-inset[3],theScreenRect[4]-newRect[2]-inset[4],pSpecifier)); #11
- end;
-
- else if (pTheFunction = 12) #12 Resize to smallest window size
- return(SizeWindow(20,20,pSpecifier)); #12
-
- else if (pTheFunction = 13) #13 Size window across screen border to second screen (if 2 screens) and back
- return(SizeAcrossScreens(pSpecifier,pDragXY)); #13
-
- else if (pTheFunction = 14) #14 Drag window across screen border and back
- return(DragAcrossScreens(pSpecifier,pDragXY)); #14
-
- else if (pTheFunction = 15) #15 Drag random location.
- return(DragWindow('RandomReturn','Random',pSpecifier)); #15
-
- else if (pTheFunction = 16) #16 Drag window back to original location.
- return(DragWindow(pDestinationPoint[1],pDestinationPoint[2],pSpecifier)); #16
-
- else if (pTheFunction = 17) #17 Zoom.
- return(ZoomWindow(pSpecifier)); #17
-
- else
- LogStr("!@#$% - scriptor error - Unknown Function Number ∂"{pTheFunction}∂" passed to WindowFunction()");
- return(0);
- end;
-
-
- #########################################################################
- # DragAcrossScreens(pSpecifier,pDragXY)
- #========================================================================
- # Author: NJV
- # Description: If there are two screens present, this task will drag
- # the window specified by <pSpecifier> so that half of the
- # window is on the first screen and half of the window
- # is on the second screen.
- # Parameters: pSpecifier - title of window to drag
- # pDragXY - a list of two co-ordinates (left-top) pixel
- # to drag window to (i.e.{0,20} to avoid menu bar
- # on main screen).
- # Returns: 1 - successful
- # 0 - unsuccessful
- # Examples: DragAcrossScreens("Untitled",{0,20}).
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK DragAcrossScreens(pSpecifier,pDragXY)
- begin
- returnVal := 0;
- failStr := '';
- # get screen information
- s1 := match [screen m:true]!;
- s2 := match [screen m:false]!;
- wind := FindWindow(pSpecifier);
-
- TCSStart({ 2, global kTCSetUIWindowDrag },"DragAcrossScreens");
- if (s2 and s1 and wind)
- begin
- # get half of the window height and half of the window width
- hWidth := ((wind.r[3] - wind.r[1])/2);
- hHeight := ((wind.r[4] - wind.r[2])/2);
-
- # assign various sides of screens to easier and shorter variables
- l1 := s1.r[1]; r1 := s1.r[3]; t1 := s1.r[2]; b1 := s1.r[4];
- l2 := s2.r[1]; r2 := s2.r[3]; t2 := s2.r[2]; b2 := s2.r[4];
-
- # determine if screen2 is to left or right of main screen
- if ((r2 = l1) or (l2 = r1)) begin
- if (t1 > t2)
- Dy := t1 + pDragXY[2];
- else
- Dy := t2;
- if (l1 < l2)
- Dx := l2 - hWidth;
- else
- Dx := l1 - hWidth;
- end;
-
- # must be above or below main screen
- else begin
- if (l1 > l2)
- Dx := l1;
- else
- Dx := l2;
- if (t1 < t2)
- Dy := t2 - hHeight;
- else
- Dy := t1 - hHeight;
- end;
-
- LogStr("Dragging window across screen borders...");
- returnVal := DragWindow(Dx,Dy);
- end;
- else if not (s2)
- failStr := "Note: Cannot drag across screens because the target doesn't have two monitors";
- else
- failStr := "Something not here couldn't DragAcrossScreens"; # - return unsuccessful
-
- if not(returnVal)
- TCSReturn := -1; # Feature not available
- else
- TCSReturn := 1;
-
- TCSEnd({ 2, global kTCSetUIWindowDrag }, TCSReturn,failStr);
- if(failStr)
- LogStr(failStr);
- return(returnVal);
- end; # DragAcrossScreens()
-
- #########################################################################
- # SizeAcrossScreens(pSpecifier,pDragXY)
- #========================================================================
- # Author: NJV
- # Description: If there are two screens present, this task will size
- # the window specified by <pSpecifier> (if there's a grow box)
- # so half of the window is on the first screen and half of
- # the window is on the second screen.
- # Parameters: pSpecifier - Descriptor of the window to size.
- # pDragXY - a list of two co-ordinates (left-top) pixel
- # to drag window to (i.e.{0,20} to avoid menu bar
- # on main screen).
- # Returns: 1 - successful
- # 0 - unsuccessful
- # Examples: SizeAcrossScreens("myWindow",{0,20}).
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK SizeAcrossScreens(pSpecifier, pDragXY)
- begin
- # BUG - if second screen is above or below main screen, the following error occurs,
- # but routine still works
- # size [window … ] w: horizontal coordinate off bounds
- returnVal := 0;
- failStr := '';
- # get screen information
- s1 := match [screen m:true]!;
- s2 := match [screen m:false]!;
-
- wind := FindWindow(pSpecifier);
-
- TCSStart({ 2, global kTCSetUIWindowSize }, "SizeAcrossScreens");
- if (s2 and s1 and wind)
- begin
- # determine smallest size of window's width and height
- SizeWindow(20,20); # attempt to size to 20,20
- newWind := FindWindow(pSpecifier);
- wWidth := newWind.r[3] - newWind.r[1];
- wHeight := newWind.r[4] - newWind.r[2];
-
- # assign various sides of screens to easier and shorter variables
- l1 := s1.r[1]; r1 := s1.r[3]; t1 := s1.r[2]; b1 := s1.r[4];
- l2 := s2.r[1]; r2 := s2.r[3]; t2 := s2.r[2]; b2 := s2.r[4];
-
- # determine if screen2 is to left or right of main screen
- if (r2 = l1) begin # screen 2 is left of screen 1
- Dx := l1 - wWidth; # put on right edge of window on left edge of screen 2
-
- # calculate top y value of window
- if (t2 > t1) begin # mid or low left - put at b1 level of screen 2
- if ((b1 - wHeight) < (t2+wHeight)) begin # can't be done
- LogStr("Screen positions do not allow for sizing across 2 monitors");
- return(ResetWindow(wind));
- end;
- Dy := t2;
- end;
- else # high-left
- Dy := b2 - wHeight;
- Sy := b1-Dy;
- Sx := wWidth + (r1-l1);
- end;
-
- else if (l2 = r1) begin # screen 2 is right of screen 1
- Dx := l2 - wWidth; # put at right of screen 1
- if (t2 > t1) # mid or low right
- Dy := t2 - wHeight;
- else begin # high right
- if ((b2 - wHeight) < (t1+wHeight)) begin # can't be done
- LogStr("Screen positions do not allow for sizing across 2 monitors");
- return(ResetWindow(wind));
- end;
- Dy := t1 + pDragXY[2];
- end;
- Sy := b2-Dy;
- Sx := wWidth + (r2-l2);
- end;
-
- # must be above or below main screen
- else begin
- if (l1 > l2)
- Dx := l2;
- else
- Dx := l1;
- if (t1 < t2) begin # screen below main screen
- Dy := t2 - wHeight;
- Sy := b2-t2+wHeight;
- Sx := r2 - Dx;
- end;
- else begin # screen above main screen
- Dy := t1 - wHeight;
- Sy := (b1-t1) + wHeight;
- Sx := r1 - Dx;
- end;
- end;
-
- DragWindow(Dx,Dy);
- LogStr("Sizing window across screen borders...");
- SizeWindow(Sx-1,Sy);
- returnVal := 1;
- end;
- else if not (s2)
- failStr := "Note: Cannot size across screens because the target doesn't have two monitors";
- else
- failStr := "Something not here - couldn't resize across screens";
-
- if not(returnVal)
- TCSReturn := -1; # Feature not available
- else
- TCSReturn := 1;
-
- TCSEnd({ 2, global kTCSetUIWindowSize }, TCSReturn,failStr);
- if(failStr)
- LogStr(failStr);
- return(returnVal);
- end; # SizeAcrossScreens()
-
-
- #########################################################################
- # AdjustRectToScreen(pTheRect)
- #========================================================================
- # Author: Nick Vaccaro
- # Description: This routine checks a rectangle to see if it is within
- # the screen, if any part of it is not, it will be
- # clipped so as to fit the screen. This is done by
- # comparing the coordinates of the rectangle with that of
- # the screen.
- # Parameters: pTheRect - holds the coordinates of the rectangle.
- # Returns: pTheRect - the coordinates of the clipped rectangle.
- # (if it was not completely within the screen)
- # or the coordinates of the original rectangle
- # (if it lies totally within the screen)
- # Examples: AdjustRectToScreen(Window.r).
- # Assumptions: All windows are no larger than the screen.
- #========================================================================
- # History:
- #
- #########################################################################
- TASK AdjustRectToScreen(pTheRect)
- begin
- screenList := collect [screen]!;
- screenCount := card screenList;
- if (screenCount = 1) begin # only one screen
- screenRect := screenList[1].r;
- Top := pTheRect[2]; # 'Top' cannot go beyond the title bar
-
- if (pTheRect[1] <= screenRect[1]) # compare left,top,right and bottom
- Left := screenRect[1]; # coordinates with screen coordinates
- else
- Left := pTheRect[1];
- if (pTheRect[3] >= screenRect[3])
- Right := screenRect[3];
- else
- Right := pTheRect[3];
- if (pTheRect[4] >= screenRect[4])
- Bottom := screenRect[4];
- else
- Bottom := pTheRect[4];
-
- pTheRect := {Left,Top,Right,Bottom};
- return(pTheRect);
- end;
- end; # AdjustRectToScreen()
-
-
-
- #########################################################################
- # CoverCompletely(pFirstWindow,pSecondWindow)
- #========================================================================
- # Author: SMQ
- # Description: This routine determines whether or not one window
- # completely covers another. This is done by comparing
- # the coordinates of both windows.
- # Parameters: pFirstWindow - specifies the first window.
- # pSecondWindow - specifies the second window.
- # Returns: 1 - second window is completely covered by the first.
- # 0 - second window is partially or totally Uncovered.
- # Examples: CoverCompletely(window1,window2).
- # Assumptions: None
- #========================================================================
- # History:
- #
- #########################################################################
- TASK CoverCompletely (pFirstWindow, pSecondWindow)
- begin
- returnVal := 0 ;
-
- firstWindow := FindWindow(pFirstWindow);
- secondWindow := FindWindow(pSecondWindow);
- firstOrd := firstWindow.o;
- firstRect := firstWindow.r;
- secondOrd := secondWindow.o;
- secondRect := secondWindow.r;
- if (firstOrd < secondOrd) begin # could be covered - let's check
- # first, adjust the rectangles - if required
- Rect2 := AdjustRectToScreen(secondRect);
- Rect1 := AdjustRectToScreen(firstRect);
- returnVal := RectInRect(Rect2,Rect1);
- end;
- return(returnVal);
- end; # CoverCompletely()
-
-
-
-
- #########################################################################
- # ResetWindow(pTheWindow)
- #========================================================================
- # Author: Nick Vaccaro
- # Description: Resets the first window with a grow and zoom box to
- # the size and position of the input parameter wind
- # window descriptor.
- # Parameters: pTheWindow - window descriptor of original window.
- # Returns: 0 - error
- # 1 - no error
- # Examples: ResetWindow(pTheWindow).
- # Assumptions: None
- #========================================================================
- # History:
- #
- #########################################################################
- TASK ResetWindow(pTheWindow)
- begin
- global OrigScrollBars;
- returnVal := 0;
-
- theWind := SelectWindow([window g:true z:true]!);
- if (theWind)
- begin
- windOrd := theWind.o;
- theTitle := theWind.t;
- windRect := theWind.r;
- theDesc := [window t:theTitle o:windOrd]!;# Partial window descriptor contains TITLE and ORD
-
- LogStr("==== Restoring window titled ∂"{theTitle}∂" to original size/location");
- SizeWindow(20,20,theDesc);
- DragWindow(pTheWindow.r[1],pTheWindow.r[2],theDesc);
- SizeWindow(pTheWindow.r[3]-pTheWindow.r[1],pTheWindow.r[4]-pTheWindow.r[2],theDesc);
- if ((not isUndefined(OrigScrollBars)) and (global OrigScrollBars))
- begin
- vert := OrigScrollBars[1];
- ScrollWindow('V',vert[1],vert[2]);
- if (card OrigScrollBars >= 2) begin
- horiz := OrigScrollBars[2]; # bug fix 6/27/91
- ScrollWindow('H',horiz[1],horiz[2]);
- end;
- end;
- LogStr("==== Done restoring window titled ∂"{theTitle}∂"");
- returnVal := 1;
- end;
- else
- Logstr("!@#$% Couldn't select the window");
- return(returnVal);
- end; # ResetWindow()
-
-
- ########################################################################
- # SelectWindow(pSpecifier)
- #=======================================================================
- # Author: NJV
- # Description: This routine will select a window specified by
- # <pSpecifier>.
- # Parameters: pSpecifier - holds the title or ordinality or window descriptor
- # of window to select.
- # Returns: {theDesc} - Updated window descriptor - Selected window OK
- # 0 - Couldn't find window to select
- #=======================================================================
- # History:
- # KTA 7/19/93 Updated theDesc so descriptor is not embedded in a list.
- ########################################################################
- TASK SelectWindow(pSpecifier := 0)
- begin
- returnVal := 0; # Init error condition
- theWind := FindWindow(pSpecifier);
- if (theWind)
- begin
- windOrd := theWind.o;
- title := theWind.t;
- windRect := theWind.r;
- if(windOrd <> 1)
- begin
- UnCoverWindow(pSpecifier);
- select [window o:windOrd t:title]!;
- Logstr("Selected window of ordinality {windOrd} (titled '{title}')");
- theDesc := [window t:title r:windRect]; # Call FindWindow with title and rect
- returnVal := FindWindow(theDesc); # return the updated window descriptor
- end;
- else # The specified window is already o:1
- returnVal := theWind;
- end;
- else
- Logstr("!@#$% Couldn't select the window");
- return(returnVal);
- end; # SelectWindow()
-
-
- ########################################################################
- # UnCoverWindow(pSpecifier, pFrontWindow)
- #=======================================================================
- # Author: Kevin Avoy
- # Description: This routine will move a window out of the way if it covers
- # our desired window.
- # Parameters: pSpecifier - holds the title or ordinality of window that is desired.
- # pFrontWindow - window that is in front of the desired one.
- # Returns: Nothing
- #=======================================================================
- # History:
- # KTA 7/20/93 Updated window descriptor so it is not contained with in a list.
- ########################################################################
- TASK UnCoverWindow(pSpecifier, pFrontWindow := 0)
- begin
- returnVal := 0;
- desiredWindow := FindWindow(pSpecifier);
- windOrd := desiredWindow.o;
- theTitle := desiredWindow.t;
- windRect := desiredWindow.r;
- theDesc := [window t:theTitle o:windOrd];
- if (windOrd <> 1) # Desired window is not the frontmost window
- begin # target window not frontmost
- match [screen r:?theScreenRect m:true]!;
- # See if there is another window in front of it
- frontWind := match [window o:?newOrd r:?FRect t:?Front g:true z:true]!;
- frontDesc := [window t:Front o:newOrd];
- if (newOrd < windOrd)
- begin
- # see if target window is covered up - if so, uncover
- coverup := CoverCompletely(frontDesc,theDesc);
- if (coverup)
- begin # move front window aside to show target window
- if (windRect[1] <= 0)
- DragWindow(20,FRect[2],frontDesc,1);
- else if (windRect[3] >= theScreenRect[3])
- DragWindow(-20,FRect[2],frontDesc,1);
- else
- DragWindow(windRect[1]+20,FRect[2],frontDesc,1);
- end;
- end;
- end;
- end;
-
- #########################################################################
- # DragWindow(pHorizontalPixels, pVerticalPixels,pSpecifier,pAbsolutely)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This routine will drag the specified window.
- # <pHorizontalPixels> pixels horizontally (negative drags left)
- # and <pVerticalPixels> pixels vertically (negative drags up)
- # Parameters: pHorizontalPixels - Horizontal pixel offset to drag the window
- # pVerticalPixels - Vertical pixel offset to drag the window
- # pSpecifier - Window specifier
- # pAbsolutely - 1 if absolute drag
- # 0 if relative drag
- # Returns: 1 - Dragged window OK
- # 0 - Couldn't find window to drag
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/21/93 Added a TCSStr to the TCSEnd call, which descibes the action
- #########################################################################
- TASK DragWindow(pHorizontalPixels := "Random", pVerticalPixels := "Random", pSpecifier := 0,pAbsolutely := 1)
- begin
- if (global gScreenInset)
- inset := gScreenInset;
- else
- inset := { 0,20,10,10};
- noErrorFlag := 0; # Init error condition
- if (pHorizontalPixels = "Random") or (pHorizontalPixels = "RandomReturn")
- begin # user wants random coordinates
- if (pHorizontalPixels = "RandomReturn")
- RandReturn := 1;
- xyRandom := getXYRandom(inset);
- pHorizontalPixels := xyRandom[1];
- pVerticalPixels := xyRandom[2];
- end;
-
- theWind := FindWindow(pSpecifier);
- if (theWind) begin
- windOrd := theWind.o;
- title := theWind.t;
-
- if (pSpecifier > 0)
- Str1 := "of ordinality {pSpecifier} ";
- else if (pSpecifier = 0)
- Str1 := "with grow and zoom box ";
- else if( not (TypeOf(pSpecifier) = 'integer'))
- Str1 := "";
- if (RandReturn) # Save original coordinates
- begin
- origH := theWind.r[1];
- origV := theWind.r[2];
- end;
- TCSStart({ 1, global kTCSetUIWindowDrag },"DragWindow"); # Start TCS
- if (pAbsolutely)
- begin
- drag [window o:windOrd t:title]! a:{pHorizontalPixels,pVerticalPixels}; #To drag the window
- str := "Dragged window {Str1}titled '{title}' to absolute location ∂({pHorizontalPixels},{pVerticalPixels}∂)";
- noErrorFlag := 1;
- end;
- else
- begin
- drag [window o:windOrd t:title]! r:{pHorizontalPixels,pVerticalPixels}; #To drag the window
- str := "Dragged window {Str1}titled '{title}' {pHorizontalPixels} pixels horizontally and {pVerticalPixels} pixels vertically";
- noErrorFlag := 1;
- end;
- TCSEnd({ 1, global kTCSetUIWindowDrag }, noErrorFlag,,,str);
- LogStr(str);
- if (RandReturn) #Move back to original location
- begin
- TCSStart({ 3, global kTCSetUIWindowDrag },"DragReturn"); # Start TCS
- drag [window o:windOrd t:title]! a:{origH,origV}; #To drag the window
- str := "Dragged window titled '{title}' back to it's original location at ∂({Origh}, {Origv}∂)";
- TCSEnd({ 3, global kTCSetUIWindowDrag }, noErrorFlag,,,str);
- LogStr(str);
- end;
- end;
- return(noErrorFlag);
- end; # DragWindow()
-
-
- #########################################################################
- # SizeWindow(pPixelsWide,pPixelsHigh,pSpecifier,pAbsolutely)
- #========================================================================
- # Author: Kevin Avoy
- # Description: This routine will match and resize the specified window.
- # If only the <pPixelsWide> and <pPixelsHigh> parameters are
- # passed, the default behavior will size the first window
- # containing a grow and zoom box pAbsolutely. If no parameters
- # are passed, then the default behavior will generate random
- # coordinates on the main screen and resize the window
- # to an absolute size. If the user passes in the string
- # "random" for <pPixelsWide> and <pPixelsHigh> and passes 0 for
- # the pAbsolutely parameter (for a resize relative to current size),
- # then checks are performed to assure that new size will
- # not go off of the screen. If it does, the values will
- # be adjusted so that the largest the window can be sized
- # is to the border of the screen.
- # Parameters: pPixelsWide - the width to resize the window
- # pPixelsHigh - the height to resize the window
- # pSpecifier - title or ordinality of window to be sized
- # pAbsolutely - 1 if resize window absolute
- # 0 if resize window relative
- # Returns: 1 - Resized window OK
- # 0 - Couldn't resize window
- # Examples: SizeWindow(200,400);
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- # KTA 12/16/93 Insure that pixels wide is not smaller than 20.
- #########################################################################
- TASK SizeWindow(pPixelsWide:="random", pPixelsHigh:="random", pSpecifier := 0, pAbsolutely := 1)
- begin
- if (global gScreenInset)
- inset := gScreenInset;
- else
- inset := { 20,20,0,0};
- noErrorFlag := 0;
- TCSReturn := 0;
- theWind := FindWindow(pSpecifier);
- pSpecifier := theWind.o;
- title := theWind.t;
- sizeBox := theWind.g;
- theWindRect := theWind.r;
-
- if (theWind)
- begin
- TCSStart({ 1, global kTCSetUIWindowSize },"SizeWindow"); # Start TCS
- if (sizeBox)
- begin
- randomFlag := 0;
- if (pPixelsWide = "random") # user wants to size window randomly
- begin
- if (inset[1] < 20 ) # Insure that we do not try to size the window to smaller than 20 pixels or
- inset := replace(20,1,inset); # VU will generate an "Out of bounds error"
-
- xyRandom := getXYRandom(inset);
- pPixelsWide := xyRandom[1];
- pPixelsHigh := xyRandom[2];
- randomFlag := 1;
- if (not pAbsolutely) # relative - include possible negative values
- begin
- negative := random(0,1);
- if (negative = 1)
- begin
- pPixelsWide := 0 - pPixelsWide;
- pPixelsHigh:= 0 - pPixelsHigh;
- end;
- end;
- end;
-
- # pSpecifier = ordinality of window to size
- # title = title of window to size
- if (randomFlag) # make sure if random numbers were generated that new window size is on screen
- begin
- match [screen r:?theScrnRect]!;
- if (pAbsolutely) # get Top-Left corner coord of window
- begin
- if ((theWindRect[1] + pPixelsWide) > theScrnRect[3]) # pPixelsWide value off of screen - adjust it
- pPixelsWide := theScrnRect[3] - theWindRect[1];
- if ((theWindRect[2] + pPixelsHigh) > theScrnRect[4]) # pPixelsHigh value off of screen - adjust it
- pPixelsHigh := theScrnRect[4] - theWindRect[2];
- end;
- else # size window relative - get Bottom-Right coord of window
- begin
- if (not negative)
- begin
- if ((theWindRect[3] + pPixelsWide) > theScrnRect[3]) # pPixelsWide value off of screen
- pPixelsWide := theScrnRect[3] - theWindRect[3];
- if ((theWindRect[4] + pPixelsHigh) > theScrnRect[4]) # pPixelsHigh value off of screen
- pPixelsHigh := theScrnRect[4] - theWindRect[4];
- end;
- ### the 20 in the equations below must be there. This is to assure that
- ### the window is not sized below 20 horizontally (the size box is 20 pixels,
- ### and attempts to size smaller than that will cause VU to display an
- ### "Out of bounds" error.
- else begin # negative value - must check against upper-left corner of screen
- if ((theWindRect[3] + pPixelsWide - 20) < theScrnRect[1]) # pPixelsWide value off of screen
- pPixelsWide := 20 - theWindRect[3] - theScrnRect[1];
- if ((theWindRect[4] + pPixelsHigh - 20) < theScrnRect[2]) # pPixelsHigh value off of screen
- pPixelsHigh := 20 - theWindRect[4] - theScrnRect[2];
- end;
- end;
- end;
- if (pAbsolutely)
- begin
- size [window t:title o:pSpecifier g:true ] W:pPixelsWide H:pPixelsHigh; #To size the window
- sizeError := ScriptError();
- if not (sizeError)
- begin
- match [window t:title o:pSpecifier g:true r:?theWindRect]!;
- pPixelsWide := theWindRect[3] - theWindRect[1];
- pPixelsHigh := theWindRect[4] - theWindRect[2];
- str := "Resized window '{title}' absolute {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
- noErrorFlag := 1;
- end;
- end;
- else
- begin
- if (randomFlag) # include negative offsets for random size
- begin
- match [window t:title o:pSpecifier g:true r:?theOrigWindRect]!;
-
- size [window t:title o:pSpecifier g:true ] r:{ pPixelsWide, pPixelsHigh }; #To size the window
- sizeError := ScriptError();
- if not (sizeError)
- begin
- match [window t:title o:pSpecifier g:true r:?theWindRect]!;
- pPixelsWide := theWindRect[3] - theOrigWindRect[3];
- pPixelsHigh := theWindRect[4] - theOrigWindRect[4];
- str := "Resized window '{title}' relative {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
- noErrorFlag := 1;
- end;
- end;
- else
- begin
- size [window t:title o:pSpecifier g:true] r:{ pPixelsWide, pPixelsHigh }; #To size the window
- sizeError := ScriptError();
- if not (sizeError)
- begin
- match [window t:title o:pSpecifier g:true r:?theWindRect]!;
- pPixelsWide := theWindRect[3] - pPixelsWide;
- pPixelsHigh := theWindRect[4] - pPixelsHigh;
- str := "Resized window '{title}' relative {pPixelsWide} pixels wide and {pPixelsHigh} pixels high";
- noErrorFlag := 1;
- end;
- end;
- end;
- end; # Is sizeBox
- else # No sizeBox
- sizeError := 1;
- ##### Error handling for Size window #####
- if (sizeError) # if there was no error, failStr = ""
- begin
- if(sizeError = -1106)
- begin
- str := "Couldn't size window, SizeBox was off screen (ScriptError = -1106)";
- TCSReturn := -1;
- end;
- else if(sizeError = -1130)
- str := "Couldn't size window, window not active (ScriptError = -1130)";
- else if(sizeError = 1)
- str := "No size box found in window titled '{title}'";
- else
- str := "Couldn't size window, an error occurred while attempting to size to coords ({pPixelsWide},{pPixelsHigh}) - (ScriptError = {sizeError})";
-
- TCSInfoStr := "";
- FailStr := Str;
- end;
- else # No sizeError (sized correctly)
- begin
- TCSReturn := noErrorFlag;
- FailStr := "";
- TCSInfoStr := "Sized window titled '{title}' to coords ({pPixelsWide},{pPixelsHigh})";
- end;
-
- TCSEnd({ 1, global kTCSetUIWindowSize }, TCSReturn, FailStr,,TCSInfoStr);
- LogStr(str);
- end;
- return(noErrorFlag);
- end; # SizeWindow()
-
-
- #########################################################################
- # ZoomWindow(pSpecifier)
- #========================================================================
- # Author: Kevin Avoy
- # Description: Selects the zoom box on the specified window. If no
- # parameters are passed, then the default behavior will
- # zoom the first window with a zoom box.
- # Parameters: pSpecifier - window specifier
- # Returns: 0 - Couldn't zoom the window
- # 1 - Zoomed the window OK
- #========================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- #########################################################################
- TASK ZoomWindow(pSpecifier:= 0)
- begin
- noErrorFlag := 0; # Init error condition
- TCSReturn := 0; # Init TCS Return value
- FailStr := ""; # Init fail string
- TCSInfoStr := "";
- theWind := FindWindow(pSpecifier);
- if theWind begin
- windOrd := theWind.o;
- title := theWind.t;
- zoomBox := theWind.z;
- theRect := theWind.r; # njv - added 6/25/91
- theHitPoint := {theRect[3]-20,theRect[2]}; # hit point for zoom box
- hitPointOffScreen := true;
-
- if (pSpecifier > 0)
- Str1 := "of ordinality {pSpecifier} ";
- else if (pSpecifier = 0)
- Str1 := "with a zoom box ";
- else if( not (TypeOf(pSpecifier) = 'integer'))
- Str1 := "";
-
- TCSStart({ 1, global kTCSetUIWindowMiscOp }, "Zoom"); # TCS Start
- if (zoomBox)
- begin
- zoom [window o:windOrd t:title]!; #To zoom the window
- zoomError := ScriptError();
-
- if (not zoomError)
- begin
- str := "Zoomed window {Str1}titled '{title}'";
- noErrorFlag := 1; # Success!
- end;
- end;
- else # No ZoomBox
- zoomError := 1;
-
- ##### Error handling for Zoom window #####
- if (zoomError) # if there was no error, failStr = ""
- begin
- if(zoomError = -1106)
- begin
- str := "Couldn't zoom window titled '{title}', ZoomBox was off screen (ScriptError = -1106)";
- TCSReturn := -1;
- end;
- else if(zoomError = -1130)
- str := "Couldn't zoom window titled '{title}', window not active (ScriptError = -1130)";
- else if(zoomError = 1)
- str := "No zoom box found in window {Str1}titled '{title}'";
- else
- str := "Couldn't zoom window titled '{title}', an error occurred (ScriptError = {sizeError})";
-
- FailStr := Str;
- end;
- else # No zoomError (zoomed correctly)
- begin
- TCSReturn := noErrorFlag; # Normally this will be a 1 indicating success
- FailStr := ""; # No FailStr since success
- TCSInfoStr := "Zoomed window titled '{title}'";
- end;
-
- TCSEnd({ 1, global kTCSetUIWindowMiscOp }, TCSReturn, FailStr,,TCSInfoStr);
- LogStr(str);
- end;
- return(noErrorFlag);
- end; # ZoomWindow()
-
- #########################################################################
- # CloseWindow(pHowClose, pOverwrite, pSpecifier,pNewDocName)
- #========================================================================
- # Author: KTA/NJV/DMM
- # Description: This routine will close the specified window. If no
- # parameters are passed to this routine, the default behavior
- # will select the close box of the first window with a close box.
- # Parameters: pHowClose - 0 - tries all three ways noted below to close the
- # window (if needed)
- # 1 - tries to close window by selecting "Close" menu
- # item
- # 2 - tries to close window by typing "Close" menu
- # item's key equivalent
- # 3 - tries to close window by selecting window's
- # close box
- # pOverwrite - 0 - will select "No" from a save-changes dialog
- # if one appears when closing window
- # 1 - will select "Yes" to save changes
- # pSpecifier - window specifier
- # pNewDocName - string holding new document name - if pOverwrite
- # parameter is 1, then pNewDocName will be used for
- # naming the file.
- # Returns: 1 - Closed window OK
- # 0 - Couldn't find window to close
- #========================================================================
- # History:
- # KTA 7/19/93 Removed theWind descriptor from being embedded in a list
- # KTA 7/23/93 Added a wait(2) prior to 'Save Document?? check also made
- # call to IsStandardFile instead of matching 'DeskTop' button.
- # KTA 8/24/93 TCS stack parity check
- # KTA 12/01/93 Enhanced check if window was closed to also check by the
- # rect of the window. (bug 1120098)
- ###########################################################################
- TASK CloseWindow(pHowClose := 3,pOverWrite := 1,pSpecifier := 0,pNewDocName :="")
- begin
- noErrorFlag := 0;
-
- theWind := FindWindow(pSpecifier); # Find the specified window
- if (theWind) begin # IF - we found the window
- ord := theWind.o; # make assignments
- theTitle := theWind.t;
- theGrow := theWind.g;
- theZoom := theWind.z;
- theRect := theWind.r;
- if (ord <> 1)
- begin
- SelectWindow(ord); # Select the window if it's not the frontmost
- theWind := FindWindow([window t:theTitle g:theGrow z:theZoom]!);
- ord := theWind.o; # Reassign Ord because selection may have changed ordinality
- end;
- if (not pHowClose) # Try all methods until one works
- pHowClose := {1,2,3};
- else
- pHowClose := {pHowClose}; # Just use the specified method
-
- numItems := Card(pHowClose);
- for i := 1 to numItems # Execute once if way to close is specified
- begin # otherwise three times attempting all methods
- closeMethod := pHowClose[i];
- if (closeMethod = 1) begin # Close with menu item
- TCSNum := 2;
- TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseFromFileMenu");
- if(SelectMenuItem("Close","File"))
- noErrorFlag := 1; # Success
- end;
- else if (closeMethod = 2) begin # Close with key equivelant
- closeKey := match[menuItem t:"Close"];
- TCSNum := 2;
- TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseFromKeyEq");
- if (closeKey.k) begin
- KeyEq(closeKey.k);
- noErrorFlag := 1; # Success
- end;
- end;
- else if (closeMethod = 3) begin # Close with close box
- TCSNum := 1;
- TCSStart({ TCSNum, global kTCSetUIWindowClose }, "CloseBox");
- if (theWind.c)
- begin
- close [window o:ord t:theTitle c:true]!;
- LogStr("Selected the close box on window titled '{theTitle}'");
- noErrorFlag := 1; # Success
- end;
- else
- LogStr("Couldn't find the close box on window titled '{theTitle}'");
- end;
-
- if (noErrorFlag) # IF - we had a success
- i := numItems; # break because window should be closed
- end;
-
- if (noErrorFlag) # IF - we had a success
- begin
- wait(2); # Wait to allow dialog to appear
- if(checkYesNo(pOverWrite)) # Check if a 'Save Document??' dialog appeared
- begin
- if(pOverWrite) # if the dialog appeared and we want to save
- begin
- if (IsStandardFile()) # check for Standard File
- begin
- SaveAs(pNewDocName,true);
- theTitle := Global gLastSavedFile;
- end;
- end;
- end;
- end;
-
- if(match [window t:theTitle r:theRect]!) # Is the window we just closed still open
- begin
- LogStr("!@#$% Sorry, the window - {theTitle} is still open");
- noErrorFlag := 0;
- end;
- TCSEnd({ TCSNum, global kTCSetUIWindowClose }, noErrorFlag); # End TCS
- end;
- return(noErrorFlag); # Return Result
- end; # CloseWindow()
-
-
- ########################################################################
- # ScrollWindow(pWhichScrollBar,pDesirePosition,pMaxPosition)
- #=======================================================================
- # Author: KTA/NJV
- # Description: This routine will scroll the specified scrollbar on
- # the active window.
- # Parameters: pWhichScrollBar = 'H' - for horizontal scrollbar
- # = 'V' - for vertical scrollbar
- # <pDesirePosition><pMaxPosition> = the fraction pDesirePosition/pMaxPosition
- # Returns: 0 - Couldn't scroll the scroll bar
- # 1 - Scrolled the scroll bar
- # Examples: ScrollWindow('H',1,2) will scroll the horizontal bar 1/2
- # Assumptions: That the scrollbars are present. This routine collects
- # only the first two scroll bars, which are assumed to be
- # the horizontal and vertical scroll bars.
- # This routine is not 100% reliable.
- #=======================================================================
- # History:
- # KTA 8/24/93 TCS stack parity check
- # KTA 9/10/93 Better check to see if scroll bars are on screen
- #########################################################################
- TASK ScrollWindow(pWhichScrollBar,pDesirePosition:=-1,pMaxPosition:=-1)
- begin
- returnVal := 0;
- failStr := '';
- theScrollBars := GetVHScrollBars();
- theScreen := match[screen];
- if (theScrollBars)
- begin
- vertical := theScrollBars[1];
- verticalDiff := vertical.s;
- horizontal := theScrollBars[2];
- horizontalDiff := horizontal.s;
-
- if (pWhichScrollBar = 'V') or (pWhichScrollBar = 'v')
- begin
- if (pDesirePosition=-1) or (pMaxPosition=-1) # generate random value
- begin
- pDesirePosition := random(0,verticalDiff[2]);
- pMaxPosition := verticalDiff[2];
- end;
- TCSNum := 1;
- TCSStart({ TCSNum, global kTCSetUIWindowScroll },"VerticalScroll"); # Start TCS
- if not(vertical.s = {0,0}) #Test to see if Scrollbars are enabled
- begin
- if (vertical.e) #Test to see if Scrollbars are enabled
- begin
- if(vertical.r[1] < theScreen.r[3])
- begin
- scroll vertical a:{pDesirePosition,pMaxPosition};
- scrollError := ScriptError();
- if not (scrollError)
- begin
- LogStr("Scrolled the vertical scroll bar Absolute ({pDesirePosition}, {pMaxPosition})");
- returnVal := 1;
- end;
- end;
- else
- begin
- LogStr("!@#$% The vertical scroll bar is off the screen");
- failStr := "!@#$% The vertical scroll bar is off the screen";
- end;
- end;
- else
- begin
- LogStr("!@#$% The vertical scroll bar was not enabled to scroll");
- failStr := "!@#$% The vertical scroll bar was not enabled to scroll";
- end;
- end;
- else
- begin
- LogStr("!@#$% The vertical scroll bar was not enabled to scroll - no thumbnail");
- failStr := "!@#$% The vertical scroll bar was not enabled to scroll - no thumbnail";
- end;
- end;
- else
- begin
- if (pDesirePosition=-1) or (pMaxPosition=-1) # generate random value
- begin
- pDesirePosition := random(0,horizontalDiff[2]);
- pMaxPosition := horizontalDiff[2];
- end;
- TCSNum := 2;
- TCSStart({ TCSNum, global kTCSetUIWindowScroll },"HorizontalScroll"); # Start TCS
- if not(horizontal.s = {0,0}) #Test to see if Scrollbars are enabled
- begin
- if (horizontal.e) #Test to see if Scrollbars are enabled
- begin
- if(horizontal.r[2] < theScreen.r[4])
- begin
- scroll horizontal a:{pDesirePosition,pMaxPosition};
- scrollError := ScriptError();
- if not (scrollError)
- begin
- LogStr("Scrolled the horizontal scroll bar absolute ({pDesirePosition}, {pMaxPosition})");
- returnVal := 1;
- end;
- end;
- else
- begin
- LogStr("!@#$% The horizontal scroll bar is off the screen");
- failStr := "!@#$% The horizontal scroll bar is off the screen";
- end;
- end;
- else
- begin
- LogStr("!@#$% The horizontal scroll bar was not enabled to scroll");
- failStr := "!@#$% The horizontal scroll bar was not enabled to scroll";
- end;
- end;
- else
- begin
- LogStr("!@#$% The horizontal scroll bar was not enabled to scroll - no thumbnail");
- failStr := "!@#$% The horizontal scroll bar was not enabled to scroll - no thumbnail";
- end;
- end;
- if(scrollError)
- begin
- if (scrollError = -1150)
- failStr := failstr + "Couldn't scroll because the scroll bar is off the screen";
- end;
- if not(returnVal)
- TCSReturn := -1; # Feature not available
- else
- TCSReturn := 1;
-
- TCSEnd({ TCSNum, global kTCSetUIWindowScroll }, TCSReturn,failStr);
- end;
- return(returnVal);
- end; # ScrollWindow()
-
- ########################################################################
- # GetVHScrollBars()
- #=======================================================================
- # Author: NJV
- # Description: This routine will return the vertical and horizontal
- # scroll bars.
- # Parameters: None
- # Returns: 0 - Couldn't find scroll bars
- # {vertical,horizontal} - list of vertical and horizontal
- # scroll bars
- # Examples: scrollBars := GetVHScrollBars();
- # Assumptions: Top of vertical scroll bar is at a lower vertical value
- # that the horizontal (i.e. the top of vertical rect is smaller
- # than the top of the horizontal scroll bar's rect).
- #=======================================================================
- # History:
- #
- #########################################################################
- TASK GetVHScrollBars() begin
- ScrollWindowlist :=collect[scrollbar];
- if not (card(ScrollWindowlist)) begin
- LogStr("!@#$% There were no recognizable scroll bars present");
- return(0);
- end;
- Rec1 := ScrollWindowlist[1];
- Rec2 := ScrollWindowlist[2];
- Rec1R := Rec1.r[1];
- Rec2R := Rec2.r[1];
-
- if (Rec1R < Rec2R) begin #To determine which scroll bar is Vertical/Horizontal
- horizontal := Rec1;
- vertical := Rec2;
- end;
- else begin
- horizontal := Rec2;
- vertical := Rec1;
- end;
- return({vertical,horizontal});
- end;
-
- #########################################################################
- # CloseAllWindows()
- #=======================================================================
- # Author: ML
- # Description: Closes all windows having a close box.
- # Parameters: None
- # Returns: Nothing
- # Assuptions: Windows have close boxes.
- #=======================================================================
- # History:
- #
- ########################################################################
- TASK CloseAllWindows()
- begin
- KeepGoingFlag := 1;
- While (KeepGoingFlag)
- begin
- if FindWindow([window c:true]!)
- KeepGoingFlag:= CloseWindow(,,[window c:true]!);
- else
- KeepGoingFlag:=0;
- end;
- end;
-
-
- #########################################################################
- # FindWindow(pSpecifier)
- #========================================================================
- # Author: DM
- # Description: FindWindow will return the descriptor of the window
- # specified by the parameter pSpecifier.
- # Parameters: pSpecifier - if string, then it holds title of window
- # if integer, then it holds ordinality of window
- # if rect, create a fake window specfier with the
- # rect as the wind.r
- # if window descriptor will match window meeting
- # the specified traits e.g. [window t:'Mywind' o:2]
- # Pass 0 to get the first document window
- # Returns: 0 - Couldn't find the window
- # descriptor - Window descriptor that meets the specified match
- # for <pSpecifier>
- # Example: FindWindow(1);
- #========================================================================
- # History:
- # KTA 7/19/93 Added support for pSpecifier type 'descriptor' removed embedding into list.
- #########################################################################
- TASK FindWindow(pSpecifier := "None")
- begin
- #Println "This is pSpecifier from FindWindow - ", pSpecifier;
- if(pSpecifier = "None")
- begin
- LogStr("Null pSpecifier passed as a parameter to FindWindow");
- theDesc := [];
- end;
- WindType := TypeOf(pSpecifier);
-
- if (WindType = 'descriptor')
- theDesc := match pSpecifier!;
- else if (WindType = 'string') or (WindType = 'regularExpression')
- begin
- theDesc := match [window t:pSpecifier]!;
- if (not theDesc)
- begin
- LogStr("!@#$% Couldn't match a window of title {pSpecifier}");
- theDesc := [];
- end;
- end;
- else if(WindType = 'integer')
- begin
- if(pSpecifier > 0)
- begin
- theDesc := match[window o:pSpecifier]!;
- if (not theDesc) begin
- LogStr("!@#$% Couldn't match a window of ordinality {pSpecifier} with a grow box");
- theDesc := [];
- end;
- end;
- else
- begin
- if(pSpecifier = 0)
- begin
- theDesc := match[window c:true g:true]!;
- if (not theDesc)
- begin
- LogStr("!@#$% Couldn't match a window with a close and grow box");
- theDesc := [];
- end;
- end;
- else
- begin
- if (pSpecifier < 0)
- begin
- scrList := collect[screen]!;
- theDesc := scrList[-pSpecifier];
- if (not theDesc)
- begin
- scrOrd:=-pSpecifier;
- LogStr("!@#$% Couldn't match a screen with ordinality {scrOrd}");
- theDesc := [];
- end;
- end;
- end;
- end;
- end;
- else if(WindType = 'list')
- begin
- if((TypeOf(pSpecifier[1]) = 'integer'))
- begin
- theDesc := [window r:pSpecifier t:"RECTANGLE" o:0];
- LogStr("Faked out FindWindow with a rectangle!!");
- end;
- else # the old way was e.g.FindWindow({[window t:'Untitled']});
- begin
- println " +++++++++ Error: Its an old FindWindow() Descriptor";
- #theDesc := match pSpecifier[1];
- end;
- end;
- #Println "This is theDesc from FindWindow - ", theDesc;
- return (theDesc);
- end; # FindWindow()
-
-
- ########################################################################
- # GetRandomPointsRelativeToWindow(pInset, pSpecifier, pNumPts)
- #=======================================================================
- # Author: Kevin Avoy
- # Description: Determines what the rectangle is for the window specified
- # as Specifier and returns a random X and Y coordinate which
- # will be inside the window if moving relative to the top
- # left corner of the screen or window.
- # Parameters: pInset - ltrb inset from screen or window
- # pSpecifier
- # Integer
- # > 0 - Ordinality window to find coords in
- # = O coords in window with s:doc g:true and c:true
- # < 0 coords in specified screen. Screen numbers
- # are negative of pSpecifier.
- # String
- # title of window to find coords in
- # {List}
- # any partial or complete window descriptor
- # Returns: myPoints - List of random X and Y. eg. { x, y }
- #=======================================================================
- ########################################################################
- TASK GetRandomPointsRelativeToWindow(pInset := { 0,20,20,20}, pSpecifier := 0, pNumPts := 1)
- begin
- theDesc := FindWindow(pSpecifier);
- if(theDesc)
- begin
- windowRect := theDesc.r;
- myPoints := GetXYRandom(pInset, windowRect, pNumPts);
- end;
- return(myPoints);
- end;
-
-
- #=======================================================================
- # Dialog related tasks:
- #=======================================================================
-
- #########################################################################
- # SelectButton(pButton)
- #========================================================================
- # Author: KTA
- # Description: This routine will select the button named <pButtonName>
- # Parameters: pButton - string - holding name of button to select
- # integer - ordinality of Button
- # Returns: 0 - Couldn't select button
- # pButtonName - Selected button OK
- #========================================================================
- # History:
- # KTA 7/6/93 Performance support: Call (gBeginTimer);
- # KTA 9/13/93 Added support for selecting Buttons for by ordinality
- # KTA 9/21/93 Changed gBeginTimer to gPreSelectButtonHook
- # KTA 9/21/93 Changed gBeginTimer to gPreSelectButtonHook
- # KTA 11/12/93 Changed select[button] to move over the button then click
- # for performance - doesn't require additional match. This
- # is done to reduce the amount of VU overhead required in matching
- # the button.
- # KTA 11/16/93 Do logging prior to actually selecting button for performance.
- # KTA 12/01/93 Added support for button descriptors.
- #########################################################################
- TASK SelectButton(pButton)
- begin
- returnVal := 0;
- ParameterType := typeOf(pButton);
- if (ParameterType = 'string')
- IsButton := match[button t:pButton]!;
- else if (ParameterType = 'integer')
- IsButton := match [button o:pButton]!;
- else if (ParameterType = 'descriptor')
- begin
- if(DescType(pButton) = 'button')
- IsButton := match pButton!;
- else
- logStr("!@#$% The descriptor '{pButton}' is not a valid button descriptor");
- end;
-
- if (IsButton)
- begin
- theButtonTitle := IsButton.t;
- if (IsButton.e)
- begin
- LogStr( "Selecting button titled '{theButtonTitle}'");
- move a:{((IsButton.r[1]+IsButton.r[3])/2),((IsButton.r[2]+IsButton.r[4])/2)};
- if (global gPreSelectButtonHook)
- Call(gPreSelectButtonHook);
- click;
- #Select [button t:theButtonTitle]!;
- returnVal := theButtonTitle;
- end;
- else
- LogStr("!@#$% Couldn't select button named '{theButtonTitle}' because it's not enabled");
- end;
- else
- LogStr("!@#$% There was no button specified by '{pButton}'");
-
- return(returnVal);
- end; # SelectButton()
-
- #######################################################################
- # SelectRadioButton(pRadioButton)
- #========================================================================
- # Author: KTA
- # Description: This routine will select RadioButton named <pRadioButtonName>
- # Parameters: pRadioButton - string - name of radio button to select
- # integer - radio button ordinality
- # Returns: 0 - Couldn't select radio button
- # pRadioButtonName - Selected button OK
- #========================================================================
- # History:
- # KTA 9/13/93 Added support for selecting radioButtons for by ordinality
- #########################################################################
- TASK SelectRadioButton(pRadioButton)
- begin
- returnVal := 0;
- if (typeOf(pRadioButton) = 'string')
- IsRadioButton := match [RadioButton t:pRadioButton]!;
- else if (typeOf(pRadioButton) = 'integer')
- IsRadioButton := match [RadioButton o:pRadioButton]!;
-
- if (IsRadioButton)
- begin
- theRadioButtonTitle := IsRadioButton.t;
- if (IsRadioButton.e)
- begin
- Select [RadioButton t:theRadioButtonTitle];
- str := "Selected radio button titled '{theRadioButtonTitle}'";
- returnVal := theRadioButtonTitle;
- end;
- else
- str := "!@#$% Couldn't select radio button named '{theRadioButtonTitle}' because it's not enabled";
- end;
- else
- str := "!@#$% There was no radio button specified by '{pRadioButton}'";
-
- LogStr(str);
- return(returnVal);
- end; # SelectRadioButton()
-
- #########################################################################
- # SelectCheckBox(pCheckBox)
- #========================================================================
- # Author: KTA
- # Description: This routine will select CheckBox named <pCheckBoxName>
- # Paramters: pCheckBox - string - name of check box to select
- # integer - ordinality of checkBox
- # Returns: 0 - Couldn't select check box
- # pCheckBoxName - Selected check box OK
- #========================================================================
- # History:
- # KTA 9/13/93 Added support for selecting CheckBox for by ordinality
- #########################################################################
- TASK SelectCheckBox(pCheckBox)
- begin
- returnVal := 0;
- if (typeOf(pCheckBox) = 'string')
- isSelectCheckBox := match [CheckBox t:pCheckBox]!;
- else if(typeOf(pCheckBox) = 'integer')
- isSelectCheckBox := match [CheckBox o:pCheckBox]!;
-
- if (isSelectCheckBox)
- begin
- theCheckBoxTitle := isSelectCheckBox.t;
- if (isSelectCheckBox.e)
- begin
- Select [CheckBox t:theCheckBoxTitle];
- str := "Selected check box titled '{theCheckBoxTitle}'";
- returnVal := theCheckBoxTitle;
- end;
- else
- str := "!@#$% Couldn't select check box named '{theCheckBoxTitle}' because it's not enabled";
- end;
- else
- str := "!@#$% There was no check box specified by '{pCheckBox}'";
-
- LogStr(str);
- return(returnVal);
- end; # SelectCheckBox()
-
-
- #########################################################################
- # CheckYesNo(pFlag)
- #========================================================================
- # Author: SL
- # Description: Checks for dialog boxes with "Yes" (or "OK") and "No"
- # buttons. If they are found, clicks one of the buttons
- # depending on the 'pFlag' parameter.
- # Parameters: pFlag - TRUE - Selects "Yes" or "OK" button.
- # FALSE - Selects "No" button.
- # DocName - Name that docment will be saved with.
- # Returns: What is returned by SelectButton
- #========================================================================
- # History:
- #
- #########################################################################
- TASK CheckYesNo(pFlag := true)
- begin
- if ( pFlag ) begin
- yesBtn := match[button t:"Yes" w:[window o:1]]!;
- okBtn := match[button t:"Ok" w:[window o:1]]!;
- saveBtn := match[button t:"Save" w:[window o:1]]!;
-
- if (yesBtn)
- return(SelectButton("Yes"));
- else if (okbtn)
- return(SelectButton("OK"));
- else if (saveBtn)
- return(SelectButton("Save"));
- end;
- else
- begin
- noBtn := match[button t:"No" w:[window o:1]]!;
- if (noBtn)
- return(SelectButton("No"));
- else
- begin
- DontSaveBtn := match[button t:"Don’t Save" w:[window o:1]]!;
- if (DontSaveBtn)
- return(SelectButton("Don’t Save"));
- end;
- end;
- end; # CheckYesNo()
-
- ########################################################################
- # DialogCheck(pFindStaticText,pCommitButton, pLogIT, pWindowDesc)
- #=======================================================================
- # Author: Kevin Avoy
- # Description: This routine will to match a dialog of specified by <pWindowDesc>,
- # with static text - <pFindStaticText>, if found it will select the
- # Button - {pCommitButton}. If <pFindStaticText> is not defined a
- # match will be made on any dialog with static text.
- # Parameters: pFindStaticText - Static text string that you want to match
- # pCommitButton - Button to select if the static text is found.
- # pLogIT - If you don't want to log the dialog pass 0
- # pWindowDesc - window descriptor of dialog
- # Returns: <Static Text> - the Static Text String found pFindStaticText
- # and selected pCommitButton
- # 0 - Couldn't find pFindStaticText
- #=======================================================================
- # History:
- # KTA 7/6/93 Changed default pWindowDesc so it doesn't include c:False
- # KTA 11/11/93 Updated so if pFindStaticText = '' it will not need to be a substring
- # KTA 11/15/93 Moved ! in collect statement so it would actually work
- # KTA 12/01/93 Added support for button descriptors
- ########################################################################
- TASK DialogCheck(pFindStaticText :='', pCommitButton :="", pLogIT := 1, pWindowDesc := [window o:1 c:false])
- begin
- returnVal := 0;
- DialogWin := collect[staticText w:pWindowDesc]!;
- if (DialogWin)
- begin
- NumStaticItems:= card (DialogWin);
- for i:= 1 to NumStaticItems
- begin
- StaticItem:= DialogWin[i];
- theStaticText := StaticItem.t;
- if not( theStaticText = '')
- begin
- if((IsSubString(pFindStaticText, theStaticText)) or (pFindStaticText = ''))
- begin
- if (pLogIT)
- LogStr("Found Dialog: '{theStaticText}'");
- if (pCommitButton)
- begin
- ParameterType := typeOf(pCommitButton);
-
- if ((ParameterType = 'string') or (ParameterType = 'descriptor'))
- SelectButton(pCommitButton);
- else if (pCommitButton = 1)
- SpecialKey(returnKey, "Return Key");
- else
- LogStr('!@#$% Method of dismissing Dialog was not valid');
- end;
- returnVal := theStaticText;
- NumStaticItems:=i;
- end; # if(IsSubString(pFindStaticText, theStaticText))
- end; # if not( theStaticText = '')
- end; # i:= 1 to NumStaticItems
- end; # if (DialogWin)
- else
- returnVal := 0;
- return(returnVal);
- end; # DialogCheck()
-
-
- #########################################################################
- # DialogHandler(pSpecifier)
- #========================================================================
- # Author: GS (x25506)
- # Description: Handle dialog exceptions.
- # Parameters: pSpecifier - dialog descriptor.
- # Returns: 0 - Unsuccessful
- # (non-zero) - Successful
- # Examples: DialogHandler();
- # Assumptions: None
- #========================================================================
- # History:
- # KTA 7/27/93 DoubleCheck for dialog because dialogCheck() will only work
- # if there is statictext
- #########################################################################
- TASK DialogHandler(pSpecifier := [window o:1 c:false]!)
- begin
- if (global gDialogHandling)
- begin
- tempGAppVer := global gAppVerify;
- gAppVerify := 0;
- counter := 0;
- DialogString := "";
- returnVal := 0;
- myDialogString := "";
- SpecifiedDialog := FindWindow(pSpecifier);
- GenericDialog:= FindWindow([window o:1 s:dialog]); # GenericDialog
-
- if((SpecifiedDialog) or (GenericDialog))
- begin
- if (match[button t:"Cancel"])
- TempDialogStr := DialogCheck(,"Cancel",,pSpecifier);
- else
- TempDialogStr := DialogCheck(,1,,pSpecifier);
-
- if (TempDialogStr)
- begin
- myDialogString := "Dialog := '{TempDialogStr}'";
- DialogString := DialogString + " / " + myDialogString;
- returnVal := DialogString;
- end;
- else
- returnVal := DismissDialog(1, pSpecifier);
- end;
- else
- begin
- #logstr ("There wasn't any dialogs to dismiss");
- returnval:= -1; # Since there is no dialog to dismiss we were successful
- end;
-
- gAppVerify := tempGAppVer;
-
- return (returnVal);
- end;
- end; # DialogHandler()
-
- #########################################################################
- # DismissDialog(pHowToDismiss, pSpecifier)
- #=======================================================================
- # Author: ML
- # Description: Generic dialog dismisser.
- # Assumptions: Window is style dialog and ordinality 1.
- # Parameters: pHowToDismiss - 1 type return key
- # {string} select button named {string}
- # Returns: 0 - dialog not dismissed
- # 1 - dialog sucessfully dismissed
- # Example: DismissDialog ('Cancel')
- #=======================================================================
- # History:
- # KTA 7/6/93 Added default value for the pHowToDismiss input parameter
- # KTA 7/7/93 Changed check to see if it actually dismissed the right dialog
- # KTA 7/19/93 changed pSpecifier so descriptor is not contained in a list
- # KTA 9/13/93 Added support for KeyEq('.') & better check to verfiy dialog
- # was dismissed.
- #########################################################################
- TASK DismissDialog (pHowToDismiss := 1, pSpecifier := [window o:1 c:false]!)
- begin
- returnval:=0;
- SpecifiedDialog:= FindWindow( pSpecifier);
- if not (SpecifiedDialog)
- SpecifiedDialog := FindWindow([window o:1 s:dialog]); # GenericDialog
-
- if (SpecifiedDialog)
- begin
- if (pHowToDismiss = 1)
- SpecialKey(returnKey , "Return Key");
- else if (TypeOf(pHowToDismiss) = 'string')
- begin
- if (pHowToDismiss = '.')
- keyEq('.');
- else
- selectbutton (pHowToDismiss);
- end;
-
- wait(2); ## Give Dialog time to disappear
- ## Check to see if dialog is still present
-
- if not ((match[window t:SpecifiedDialog.t r:SpecifiedDialog.r c:SpecifiedDialog.c g:SpecifiedDialog.g z:SpecifiedDialog.z]!))
- begin
- logstr('Dismissed dialog');
- returnval:=1;
- end;
- else
- logstr('Unable to dismiss dialog');
- end; # if SpecifiedDialog
- else
- begin
- logstr ('No dialog to dismiss');
- returnval:=1; # Since there is no dialog to dismiss we were successful
- end;
- return(returnVal);
- end; # DismissDialog()
-
-
-
- #=======================================================================
- # Mouse action related tasks:
- #=======================================================================
-
-
- #########################################################################
- # MoveRelativeToWindow(pHorizontalPixels, pVerticalPixels, pSpecifier,pMouseDown,pInset)
- #========================================================================
- # Author: NJV
- # Description: This routine will calculate the window's rectangle
- # and add pHorizontalPixels and pVerticalPixels input parameters
- # to the rectangle's top-left coordinate point. It will then
- # move the mouse to that location. The window is
- # specified by the pSpecifier input parameter. If the
- # pSpecifier parameter is not present, the default
- # behavior will move relative to the frontmost document window.
- # Parameters: pHorizontalPixels - int representing left (pHorizontalPixels) coord
- # or List of points.
- # pVerticalPixels - int representing top (pVerticalPixels) coord
- # pSpecifier - holds title or ordinality of window
- # 0 matches first s:document c:true g:true window
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # pHorizontalPixels is ptList 3 - MultiDrag (pressmouse - move - move - move - release)
- # 4 - move - release
- # pHorizontalPixels is ptList 5 - MultiClick (click - move - click - move - click)
- # pInset - inset from window rect for GetXYRandom
- # WhichCorner - Relative to which corner of the window
- # 1 - Top/Left
- # 2 - Bottom/Left
- # Returns: Nothing
- # Examples: MoveRelativeToWindow(12,25);
- # Assumptions: Assumes there is a window on the screen
- #========================================================================
- # History:
- # KTA 7/6/93 Performance support: Call (gBeginTimer);
- # KTA 7/6/93 Move Performance Support into MoveMouse()
- #########################################################################
- TASK MoveRelativeToWindow(pHorizontalPixels:= 'random', pVerticalPixels:= 'random', pSpecifier:=0,pMouseDown:=0,pInset:= {30,30,30,30}, WhichCorner := 1)
- begin
- returnVal := 0; # Init error condition
- if ( pHorizontalPixels='random') begin # user wants random mouse move
- xyRandom := GetRandomPointsRelativeToWindow(pInset, pSpecifier);
- pHorizontalPixels := xyRandom[1];
- pVerticalPixels := xyRandom[2];
- returnVal := xyRandom;
- end;
- theWind := FindWindow(pSpecifier);
- if theWind
- begin
- lvWindRect := theWind.r;
- if(whichCorner = 1) # Top/Left Corner
- begin
- lvX := lvWindRect[1];
- lvY := lvWindRect[2];
- end;
- else if(whichCorner = 2) # Bottom/Left
- begin
- lvX := lvWindRect[1];
- lvY := lvWindRect[4];
- end;
- else if(whichCorner = 3) # Bottom/Right
- begin
- lvX := lvWindRect[3];
- lvY := lvWindRect[4];
- end;
- else if(whichCorner = 4) # Top/Right
- begin
- lvX := lvWindRect[3];
- lvY := lvWindRect[2];
- end;
- # Handle PointList
- if (typeOF(pHorizontalPixels) = "list") # Need to move to a list of coordinates
- begin
- MoveMouse(pHorizontalPixels,{lvX,lvY},1,pMouseDown); # move to the calculated location
- returnVal := {lvX,lvY};
- end;
- else
- begin
- lvFinalLeft := pHorizontalPixels + lvX; # calculate absolutely pHorizontalPixels
- lvFinalTop := pVerticalPixels + lvY; # calculate absolutely pVerticalPixels
- MoveMouse(lvFinalLeft,lvFinalTop,1,pMouseDown); # move to the calculated location
- returnVal := {lvFinalLeft,lvFinalTop};
- end;
- end;
- return (returnVal);
- end; # MoveRelativeToWindow()
-
-
- #########################################################################
- # MoveMouse(pHorizontalPixels, pVerticalPixels, pAbsolutely, pMouseDown)
- #========================================================================
- # Author: DMM
- # Description: This routine will move the mouse pHorizontalPixels,pVerticalPixels
- # relative to its current location If pHorizontalPixels and
- # pVerticalPixels are absent or equal to "random", a random move is generated.
- # Parameters: pAbsolutely - 1 if move pAbsolutely, 0 if relative
- # pHorizontalPixels - horizontal distance in pixels to move mouse
- # pVerticalPixels - vertical distance in pixels to move mouse
- # if pHorizontalPixels and pVerticalPixels are absent
- # or := "random" then a random move is generated.
- # pAbsolutely - 1 to move to absolute location
- # 0 to move relative to current location
- # pMouseDown - 0 - don't hold mouse key down while moving
- # 1 - press mouse key down - move - release
- # 2 - Click after moving - no mouse down during move
- # 3 - press mouse key down - move - don't release
- #pHorizontalPixels is List 3 - MultiDrag
- # 4 - move - release
- #pHorizontalPixels is List 5 - MultiClick
- # Returns: Nothing
- #========================================================================
- # History:
- # KTA 9/21/93 Added gPreMoveMouseHook
- #########################################################################
- TASK MoveMouse(pHorizontalPixels := 'random', pVerticalPixels := 'random', pAbsolutely := 1, pMouseDown := 0)
- begin
- if ( pHorizontalPixels='random') begin # user wants random mouse move
- xyRandom := getXYRandom();
- pHorizontalPixels := xyRandom[1];
- pVerticalPixels := xyRandom[2];
- end;
-
- if ((pMouseDown = 1) or (pMouseDown = 3))
- PressMouse;
- wait(1); #
- #### To Handle PointLists #####
- if (typeOF(pHorizontalPixels) = "list") # Need to move to a list of coordinates
- begin
- pointList := pHorizontalPixels;
- xOffSet := 0;
- yOffSet := 0;
- if (typeOF(y) = "list") # If its relative to window
- begin # We pass in pVerticalPixels as the offset of the window
- xOffSet := pVerticalPixels[1];
- yOffSet := pVerticalPixels[2];
- end;
- if (pMouseDown = 5) # To start the multiClick
- click;
-
- for each pairPoints in pointList
- begin
- nuX := pairPoints[1];
- nuY := pairPoints[2];
- pHorizontalPixels := nuX + xOffSet; # If relative to window offset
- pVerticalPixels := nuY + yOffSet; # otherwise the offset is 0
-
- if(global gPreMoveMouseHook)
- Call(gPreMoveMouseHook);
-
- if (pAbsolutely)
- move a: { pHorizontalPixels, pVerticalPixels };
- else
- move r: { pHorizontalPixels, pVerticalPixels };
-
- if (pMouseDown = 5) # Click for Multiclick
- click;
- end;
- if (pMouseDown = 3) # Finished MultiDrag
- releaseMouse;
- end;
- else
- begin
- if(global gPreMoveMouseHook)
- Call(gPreMoveMouseHook);
-
- if (pAbsolutely) begin
- move a: { pHorizontalPixels, pVerticalPixels };
- str := "Moved the mouse to absolute location ∂({pHorizontalPixels},{pVerticalPixels}∂)";
- end;
- else begin
- move r: { pHorizontalPixels, pVerticalPixels };
- str := "Moved the mouse relative ∂({pHorizontalPixels},{pVerticalPixels}∂) to previous position";
- end;
-
- wait(1);
- # release mouse if needed
- if ((pMouseDown = 1) or (pMouseDown = 4))
- ReleaseMouse;
-
- # add mouse down to log string if needed
- if ((pMouseDown = 1) or (pMouseDown = 3) or (pMouseDown = 4))
- str := "{str} with mouse button held down";
-
- # click if needed
- if (pMouseDown = 2 ) begin
- Click;
- str := "{str} and clicked";
- end;
-
- # log it
- LogStr(str);
- end;
- end; # MoveMouse()
-
-
- #=======================================================================
- # Keyboard action related tasks:
- #=======================================================================
-
- #########################################################################
- # TypeStr(pTheString)
- #========================================================================
- # Author: KTA
- # Description: This routine will type the string that is passed in as
- # the <pTheStringing>.
- # Parameters: pTheString - The string to be typed
- # Returns: Nothing
- # Note: If gTypeStrOverRide is defined as a task reference, it will have to handle
- # all actions all of the functionality of TypeStr since it is being overriden.
- #========================================================================
- # History:
- # KTA 12/2/93 Added gTypeStrOverRide
- #########################################################################
- TASK TypeStr(pTheString :='')
- begin
- if (global gTypeStrOverRide)
- call (gTypeStrOverRide, pTheString);
- else
- begin
- type k:{pTheString};
- LogStr("Typed '{pTheString}'");
- end;
- end; # TypeStr()
-
-
- #########################################################################
- # TypeList(pStringList,pSpecialKey, pTypeFinalKey)
- #========================================================================
- # Author: KTA
- # Description: This routine will type each item in the {pStringList}
- # and the selected special key, designated by the <pSpecialKey>
- # input parameter, after each item. If pTypeFinalKey = 0 the
- # special key will be suppressed after the last item.
- # Parameters: pStringList - list holding strings to type
- # pSpecialKey - integer representing key to type after the item has
- # been typed.
- # pSpecialKey := 0 Nothing
- # pSpecialKey := 1 (ReturnKey)
- # pSpecialKey := 2 (TabKey)
- # pSpecialKey := 3 (EnterKey)
- # pSpecialKey := 4 (UpArrowKey)
- # pTypeFinalKey - 1 to type special key after last item in <pStringList>
- # 0 to disable typing of last special key
- # Return Value: None
- # Examples: TypeList({'A','list', 'of items'},2); To type each item
- # and then the tabKey
- # Assumptions: None
- #========================================================================
- # History:
- #
- ################################################################################
- TASK TypeList(pStringList,pSpecialKey := 0, pTypeFinalKey := 0)
- begin
- theWholeList := card(pStringList);
- for numtimes := 1 to theWholeList
- begin
- if(TypeOf(pSpecialKey) = 'integer')
- begin
- if (pSpecialKey = 1)
- KeyList := {ReturnKey,' and the Return Key'};
- else if (pSpecialKey = 2)
- KeyList := {TabKey,' and the Tab Key'};
- else if (pSpecialKey = 3)
- KeyList := {EnterKey,' and the Enter Key'};
- else if (pSpecialKey = 4)
- KeyList := {UpArrowKey,' and the Up Arrow Key'};
- end;
- else
- KeyList := {pSpecialKey,' and some Special Key???'};
- KeyName := KeyList[2];
- Item := pStringList[numtimes];
- Type k:{ Item };
- if not (numtimes = theWholeList)
- begin
- Type K:{KeyList[1]};
- end;
- else
- if(pTypeFinalKey)
- Type K:{KeyList[1]};
- else
- KeyName := '';
- LogStr("Typed '{item}'{KeyName}");
-
- end;
- end; # TypeList()
-
-
- #########################################################################
- # SpecialKey( pTheKey, pKeyName, pNumTimes )
- #========================================================================
- # Author: KTA
- # Description: This routine will type whatever SpecialKey is entered
- # However it will only log the name of the special character
- # if the special key name is also passed in as a String in
- # the pKeyName parameter.
- # Parameters: pTheKey - the VU key-word for the special key to be typed
- # (i.e. ReturnKey, TabKey, EnterKey, etc.)
- # pKeyName - the string name of the special key
- # pNumTimes - number of times to type the special key (default = 1)
- # Returns: Nothing
- # Examples: SpecialKey(TabKey,"TabKey");
- #========================================================================
- # History:
- # KTA 7/6/93 Performance support: Call (gBeginTimer);
- # KTA 9/21/93 Changed gBeginTimer to gPreSpecialKeyHook
- # KTA 11/18/93 Log prior to performing the action
- #########################################################################
- TASK SpecialKey( pTheKey, pKeyName := "", pNumTimes := 1 )
- begin
- StrExt := "";
- if (pNumTimes <> 1)
- StrExt := "- ({pNumTimes}) times";
-
- if (pKeyName ="")
- LogStr("Typing some special key {StrExt}");
- else
- LogStr ("Typing {pKeyName} {StrExt}");
-
- for x := 1 to pNumTimes
- begin
- if (global gPreSpecialKeyHook)
- Call (gPreSpecialKeyHook);
-
- type k:{ pTheKey };
- end;
- end; # SpecialKey()
-